﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Helper
{
    public static class DateTimeHelper
    {
        public static bool IsSameWeek(DateTime d1, DateTime d2)
        {

            DateTime weekStart = GetWeekStartTime(d1);
            DateTime weekEnd = GetWeekEndTime(d1);
            if (weekStart <= d2 && d2 < weekEnd)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static DateTime GetWeekStartTime(DateTime d)
        {
            int weekDay = (int)d.DayOfWeek;
            if (weekDay == 0) weekDay = 7;
            DateTime weekStartTime = d.Date.AddDays(-weekDay + 1);
            return weekStartTime;
        }

        public static DateTime GetWeekEndTime(DateTime d)
        {
            DateTime weekStartTime = GetWeekStartTime(d);
            DateTime weekEndTime = weekStartTime.AddDays(7);
            return weekEndTime;
        }

        public static bool IsSameMonth(DateTime d1, DateTime d2)
        {
            DateTime monthStart = GetMonthStartTime(d1);
            DateTime monthEnd = GetMonthEndTime(d1);
            if (monthStart <= d2 && d2 < monthEnd)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static DateTime GetMonthStartTime(DateTime d)
        {
            return new DateTime(d.Year, d.Month, 1);
        }

        public static DateTime GetMonthEndTime(DateTime d)
        {
            DateTime monthStart = GetMonthStartTime(d);
            return monthStart.AddMonths(1);
        }

        public static DateTime GetDayStartTime(DateTime d)
        {
            return d.Date;
        }

        public static DateTime GetDayEndTime(DateTime d)
        {
            return d.Date.AddDays(1);
        }

        public static bool IsSameDate(DateTime d1, DateTime d2)
        {
            return d1.Date == d2.Date;
        }

        public static DateTime GetYearStartTime(DateTime d)
        {
            return new DateTime(d.Year, 1, 1);
        }

        public static DateTime GetYearEndTime(DateTime d)
        {
            return new DateTime(d.Year, 1, 1).AddYears(1);
        }

        public static bool IsSameYear(DateTime d1, DateTime d2)
        {
            return d1.Year == d2.Year;
        }


    }
}
